﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.ComponentModel;

namespace StateMachine
{
    public class State : INotifyPropertyChanged
    {

        private TransitionCollection _transitions;
        public TransitionCollection Transitions
        {
            get { return _transitions; }
            set
            {
                _transitions = value;
                NotifyPropertyChanged("Transitions");
            }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set
            {
                _name = value;
                NotifyPropertyChanged("Name");
            }
        }

        private Point _location;
        public Point Location
        {
            get { return _location; }
            set
            {
                _location = value;
                NotifyPropertyChanged("Location");
            }
        }

        private string _id;
        public string Id
        {
            get { return _id; }
            set
            {
                _id = value;
                NotifyPropertyChanged("Id");
            }
        }

        private string _label;
        public string Label
        {
            get { return _label; }
            set
            {
                _label = value;
                NotifyPropertyChanged("Label");
            }
        }

        private bool _isFinal;
        public bool IsFinal
        {
            get { return _isFinal; }
            set
            {
                _isFinal = value;
                NotifyPropertyChanged("IsFinal");
            }
        }

        private bool _isInitial;
        public bool IsInitial 
        { 
            get { return _isInitial; } 
            set 
            {
                _isInitial = value;
                NotifyPropertyChanged("IsInitial");
            } 
        }

	   private bool _showLabel;
	   public bool ShowLabel
	   {
		   get { return _showLabel; }
		   set
		   {
			   _showLabel = value;
			   NotifyPropertyChanged("ShowLabel");
		   }
	   }

        private static int uniqueId = 0;
	    private static int UniqueId { get { return ++uniqueId; } }

        public State()
        {
            Id = UniqueId.ToString();
 		    Transitions = new TransitionCollection();
        }

		public State(string Id)
		{
			this.Id = Id;
		}

        public override string ToString()
        {
            StringBuilder result = new StringBuilder();
            result.AppendLine("Name: " + Name);
            result.AppendLine("Id: " + Id);
            result.AppendLine("Final: " + IsFinal);
            result.AppendLine("Initial: " + IsInitial);
            for (int i = 0; i < Transitions.Count; i++)
            {
                result.AppendLine("\t" + (i+1) + ". " + Transitions[i].ToString());
            }
            return result.ToString();
        }



        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string name)
        {
            if(PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

        #endregion
    }
}
